package com.bigevent.bigevent.controller;

import com.bigevent.bigevent.entity.Category;
import com.bigevent.bigevent.entity.Result;
import com.bigevent.bigevent.po.RegistCategoryPo;
import com.bigevent.bigevent.po.UpdateCategoryPo;
import com.bigevent.bigevent.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author yangxudong
 * @description: 分类controller
 * @date 2024/2/10 11:34
 */
@RestController
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @PostMapping
    public Result addCategory(@RequestBody @Validated RegistCategoryPo categoryPo) {
        categoryService.addCategory(categoryPo);
        return Result.success();
    }

    @GetMapping
    public Result<List<Category>> getCategoryList() {
        return Result.success(categoryService.getCategoryList());
    }

    @GetMapping("/detail")
    public Result<Category> getCategoryDetail(@RequestParam("id") Integer id) {
        return Result.success(categoryService.getCategoryDetail(id));
    }

    @PutMapping
    public Result updateCategory(@RequestBody @Validated UpdateCategoryPo categoryPo) {
        categoryService.updateCategory(categoryPo);
        return  Result.success();
    }

    @DeleteMapping
    public Result deleteCategory(@RequestParam("id") Integer id) {
        categoryService.deleteCategory(id);
        return Result.success();
    }
}
